package com.kang.dao.impl;

import com.kang.dao.UserDao;
import com.kang.entity.User;
import com.kang.util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 12904 on 2018/8/6.
 */
public class UserDaoImpl implements UserDao
{
    @Override
    public List<User> findUser(int uid)
    {
        List<User> list = new ArrayList<User>();
        Connection conn = null;
        PreparedStatement stat = null;
        ResultSet rs = null;
        String sql = "SELECT * FROM `user` WHERE utype = ?";
        sql += " and uid = ?";
        conn = BaseDao.getConnection();
        try {
            stat = conn.prepareStatement(sql);
            stat.setInt(1,new User_typeDaoImpl().find());
            stat.setInt(2,uid);
            rs = stat.executeQuery();
            while (rs.next()){
                User user = new User();
                user.setUid(rs.getInt("uid"));
                user.setUname(rs.getString("uname"));
                user.setUphone(rs.getString("uphone"));
                user.setUpassword(rs.getString("upasswrod"));
                user.setUprovince(rs.getInt("uprovince"));
                user.setUcity(rs.getInt("ucity"));
                user.setUcounty(rs.getInt("ucounty"));
                user.setUaddress(rs.getString("uaddress"));
                user.setUsex(rs.getString("usex"));
                user.setUtype(rs.getInt("utype"));
                user.setCreateTime(rs.getString("createTime"));
                user.setOpenid(rs.getString("openid"));
                user.setCheck(rs.getInt("check"));
                user.setUimage(rs.getString("uimage"));
                user.setUemail(rs.getString("uemail"));
                list.add(user);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeConnection(conn,stat,rs);
        }

        return list;
    }



}
